<?php
  //Buffer larger content areas like the main page content
  ob_start();
include("config.php");

    require_once("auth.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script>
function funhide()
{
document.getElementById('tc2').style.display="block";
document.getElementById('tc1').style.display="none";
}
</script>
<script type="text/javascript" src="js/validationprod.js"></script>
<script>
var count=0;

function load(thediv, thefile) /* 2 parameters passed into here: the id of the div container and the name of the page to go to */
{  
    if (window.XMLHttpRequest)
    {
        xmlhttp = new XMLHttpRequest();
    }
    else
    {
        xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');  
    }
    xmlhttp.addEventListener("error", transferFailed, false);  
    xmlhttp.onreadystatechange = function()
    {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
        {
            document.getElementById( thediv ).innerHTML = xmlhttp.responseText;
        }
    }  
 
   xmlhttp.open('GET', thefile, true);
    xmlhttp.send();
	    
}

function transferFailed(evt) {  
  alert("An error occurred while transferring the file.");  
}

</script>

</head>
<body>
<?php 
if(isset($_REQUEST['id']))
{

$id=$_REQUEST['id'];
$data=mysql_query("select * from products where serial='$id'");
$no=mysql_num_rows($data);
if($no!=0)
{
	while($rec=mysql_fetch_assoc($data))
	{
?>

<form action="updateproducts.php" method="post"  enctype="multipart/form-data" id="frmProducts">
<fieldset >
<legend style="color:#FD0002">Update Products </legend>
			<div id="status"></div>

<table width="50%"  align="center">
<tr> <td>Product Name<span style="color:#FF0000">*</span></td><td><input type="hidden" value="<?php echo $id; ?>"  name="id" /><input type="text" name="txtProductName" id="txtProductName" value="<?php echo $rec['name'];?>" ></td></tr>
<tr> <td>Technical Specifications<span style="color:#FF0000">*</span></td><td><textarea id="texttechspec" name="texttechspec"><?php echo $rec['description']; ?></textarea></td></tr>
 <tr><td colspan="2">
	<div>
	
					<table  width="100%"id="tc1">
						  <tr><td width="32%"> <input type="hidden" id="txtid" value="<?php echo $rec['picture'];?>"  name="txtoldtechname"/><img src="<?php
						 echo $rec['picture']; ?>" width="100px" height="100px" /><br /> <input type="hidden" value=" <?php echo $rec['picture']; ?>" id="pic" /></td>
						  <td width="68%" colspan="2">&nbsp;&nbsp;
											Do you want to Replace the File<br>
											&nbsp;&nbsp;<a href="#" onClick="funhide();"> Click Here To Upload Other One</a>
						</td>
						  </tr>
				  </table>
				  <table id="tc2" style="display:none" width="100%">							<tr>
							<td width="186"  class="classalign">Picture<span style="color:#FF0000">*</span>:&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
					<td width="348"><input type="file" name="filePicture" id="filePicture"><input type="hidden" name="ivalue" value="3" id="someVar"/>
</td>
							</tr>
				</table>
			
</div>
</td></tr>
<tr><td>Category</td><td><select name="ddlcat" id="ddlcat">
					<?php
					$qry=mysql_query("select * from categorys");
					$no=mysql_num_rows($qry);
					if($no>0)
					{
					while($row=mysql_fetch_assoc($qry))
					{
					?><option <?php if($rec['category']==$row['catname']) echo "selected='selected'"; ?>><?php echo $row['catname']; ?></option>				
					
					<?php
					}
					
					}
					?>
					</select>



</td></tr>
<tr><td>Price</td><td><input type="text" name="txtPrice" id="txtPrice" value="<?php echo $rec['price'];?>"  onkeypress="return numbersonly(event);"/></td></tr>
<tr><td colspan="2" align="right"><input type="button" name="btnUpdateProduct" id="btnUpdateProduct" value="Update Product" onclick="validateForm2('updateproducts.php','frmProducts','thediv','<img src=\'pleasewait.gif\'>');" /> </td></tr>
</table>
</fieldset>
  	</form>
<?php
}
}}
else
{
?>
<form action="addproducts.php" method="post"  enctype="multipart/form-data" id="frmProducts">
<fieldset >
<legend style="color:#FD0002">Add Products </legend>
<div id="status"></div>

<table width="50%"  align="center">
<tr> <td>Product Name<span style="color:#FF0000">*</span></td><td><input type="text" name="txtProductName" id="txtProductName"></td></tr>
<tr> <td>Technical Specifications<span style="color:#FF0000">*</span></td><td><textarea id="texttechspec" name="texttechspec"></textarea></td></tr>
<tr> <td>Upload Image<span style="color:#FF0000">*</span></td><td><input type="hidden"  id="pic" /><input type="file" id="filePicture" name="filePicture" /><input type="hidden" name="ivalue" value="3" id="someVar"/>
</td></tr>
<tr><td>Category</td><td><select name="ddlcat" id="ddlcat">
					<?php
					$qry=mysql_query("select * from categorys");
					$no=mysql_num_rows($qry);
					if($no>0)
					{
					while($row=mysql_fetch_assoc($qry))
					{
					?><option><?php echo $row['catname']; ?></option>				
					
					<?php
					}
					
					}
					?>
					</select>



</td></tr>

<tr><td>Price<span style="color:#FF0000">*</span></td><td><input type="text" name="txtPrice" id="txtPrice"  onkeypress="return numbersonly(event);"/></td></tr>
<tr><td colspan="2" align="right"><input type="button" name="btnAddProduct" id="btnAddProduct" value="Add Product" onclick="validateForm2('addproducts.php','frmProducts','thediv','<img src=\'pleasewait.gif\'>');" /></td></tr>
</table>
</fieldset>
  	</form>
	<?php
	}
	?>
</body>
</html>
 <?php
  //Assign all Page Specific variables
  $pagemaincontent = ob_get_contents();
  ob_end_clean();
  $pagetitle = "Products";
  //Apply the template
  include("master.php");
?>    